#include "StreamIO.h"
#include "MC.h"
#include "OSProc.h"
#include "length.h"
#include "MutexLock.h"
extern volatile _mch kmemory; 

constexpr _ptlong ADDR(const _ptlong& x) {return ((_ptlong)(&x));}
#define HWREG(x)    (*((volatile _ptlong*)(x)))


#define _maprecord  map<_length,_length>


#define ROOT             (NOW->root)
#define SWAProot         (FindStream("SWAP",ROOT))


#define IFDSWAProot      (HWREG(ADDR(SWAPpro)         - sizeof(_fstr)))
#define SWAPpro          (HWREG(ADDR(MapLock)         - sizeof(_ptlong)))
//#define SWAPmap          (HWREG(ADDR(MapLock)         - sizeof(    
#define MapLock          (HWREG(ADDR(MapRecord)       - sizeof(_mlock)))
#define MapRecord        (HWREG(ADDR(SWAPBaseLock)    - sizeof(_maprecord)))
#define SWAPBaseLock     (HWREG(ADDR(SWAPBasequeue)   - sizeof(_mlock)))
#define SWAPBasequeue    (HWREG(ADDR(StaticBaseLock)  - sizeof(Spareoffsetqueue)))
#define StaticBaseLock   (HWREG(ADDR(StaticBasequeue) - sizeof(_mlock)));
#define StaticBasequeue  (HWREG(ADDR(_SwapMemory)     - sizeof(Spareoffsetqueue))) 
#define _SwapMemory      (HWREG(SWAPMemoryStart))

#define _SwapMemoryInit() (MemoryControlInit(&_SwapMemory,_SwapMemoryStart,_SwapMemorySize))
#define _SwapMemory       (0x0)
#define _SwapMemoryStart  (0x100000)
#define _SwapMemorySize   (_DFPS_MEM_DOWN - _SwapMemoryStart)
#define _Malloc(size)  Kmalloc(&_SwapMemory,size)  
#define _Free(ptr)    Kfree(&_SwapMemory,ptr)
#define _KMalloc(size) Kmalloc(&kmemory,size)
#define _KFree(ptr)   Kfree(&kmemory,ptr)

